package com.takepoints.mobile.db;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class DatabaseHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = "tpdata.db";
	
	public DatabaseHelper(Context context){
		super(context, DATABASE_NAME, null, 1);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db){
		Cursor c = null;
		try{
			c = db.rawQuery("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'mycards'", null);
			if(c.getCount() == 0){
				db.execSQL("CREATE TABLE mycards(_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, value REAL);");
				ContentValues cv = new ContentValues();
				
			}
		} finally{
			if(c != null){
				c.close();
			}
		}
	}
	
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		android.util.Log.w("Constants", "Upgrading database, which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS constants");
	    onCreate(db);
	}
	
}
